/**
 * 行业一级分类维护 - 编辑页面
 * @author miaoyl
 * @date 2018/01/09
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        vueData = {
            isAdd: false,
            isDetail: false,
            form: '',
            rules: {
                GWBW001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBWL003: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBWL004: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWBWACTI: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions:{
                sys_y_n:app.datas_("sys_y_n")
            }
        },
        callObj
    ;

    var GwbwEdit = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'gwai236_edit',
            }, win);
        },
        editGwbw: function () {
            app.ajax({
                xurl: 'crm/gwai236/edit',
                xdata: vueData.form,
                loading: true,
                okmsg: '行业一级分类信息修改成功',
                cb: function (result) {
                    if (result.ok) {
                        //同步更新缓存对应的值
                        callObj.update(result.xdata);
                        layer.close(layer.index);
                    }
                }
            });
        },
        addGwbw: function () {
            app.ajax({
                xurl: 'crm/gwai236/add',
                xdata: vueData.form,
                loading: true,
                okmsg: '行业一级分类信息保存成功',
                cb: function (result) {
                    if (result.ok) {
                        app.pageModule('gwbw').reloadTableCurr();
                        layer.close(layer.index);
                    }
                }
            });
        },
        _call: function (obj) {
            if(obj.is_detail){
                vueData.isDetail = true;
            }else {
                vueData.isDetail = false;
            }
            if (obj.is_add) {
                vueData.isAdd=true;
                // app.log(obj);
                app.extendUpLow({
                    target: vueData.form,
                    res: {
                        GWBWACTI:'Y'
                    },
                    reset: true
                });
            } else {
                vueData.isAdd = false;
                callObj = obj.obj;
                app.extendUpLow({
                    target: vueData.form,
                    res: callObj.data,
                    reset: true
                });
            }

        },
        _ready: function () {
            vueData.form = app.fields_(['GWBW']);
            var vue = new Vue({
                el: '#gwai236_edit',
                data: vueData,
                methods: {
                    cancel: function () {
                        layer.close(layer.index);
                    },
                    sure: function () {
                        this.$refs['form'].validate(function (valid) {
                            if (valid) {
                                if (vueData.isAdd) {
                                    self.addGwbw();
                                } else {
                                    self.editGwbw();
                                }
                            }
                        });
                    }
                },
                watch: {},
                created: function () {
                    self._setEleIsReady('gwai236_edit');
                }
            });
        },
        _lazy: function () {
            this._super();
        }
    });

    return new GwbwEdit();

});